﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WFcontrol
{
    public partial class Frm_danhmuc : Form
    {
        public Frm_danhmuc()
        {
            InitializeComponent();
        }
      // accessdata con = new accessdata();
       // DataTable tb_danhmuc;
        BindingManagerBase db;
          WFcontrol.BL.cl_Danhmuc clDM;
        private void Frm_danhmuc_Load(object sender, EventArgs e)
        {
            clDM = new WFcontrol.BL.cl_Danhmuc(this);
            clDM.hienthi(null);
        //    db = this.BindingContext[tb_danhmuc];
            /*Load_Grid();
            db = this.BindingContext[tb_danhmuc];
            //con.Open();
            //DataTable tb = con.Get_DataTable("select * from Danhmuc");
            //this.dataGridView1.DataSource = tb;
            //con.Close();
             * */
        }

        private void button1_Click(object sender, EventArgs e)
        {
           /* con.Open();
            this.dataGridView1.DataSource = con.Execute_Ps("ps_danhmuc", textBox2.Text,textBox1.Text);
           // String SQL = "insert into DanhMuc(MaDM,TenDM)" + "Values('" + textBox1.Text + "','" + textBox2.Text + "')";
          //  con.Execute_SQL(SQL);

            Load_Grid();
            //DataSet ds = new DataSet();
            //ds = con.Get_DataSet(ref ds, "select * from Danhmuc");
            //this.dataGridView1.DataSource = ds.Tables[0];
            //con.Close();
             
            */
            //string madm = textBox1.Text;
            //string tendm = textBox2.Text;
            //clDM = new WFcontrol.BL.cl_Danhmuc(this);
            //clDM.them(madm, tendm);
           // clDM = new WFcontrol.BL.cl_Danhmuc(this);
            clDM.themmoi();
            dataGridView1.Refresh();
        }

        private void btn_xoa_Click(object sender, EventArgs e)
        {
          /*  con.Open();
            if(MessageBox.Show("Bạn có chắc chắn xóa ko?","thông bao",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning)==DialogResult.OK)
            {
                String SQL = "delete from DanhMuc where MaDM= '" + textBox1.Text + "'";
                con.Execute_SQL(SQL);
            }
            Load_Grid();
            //DataSet ds = new DataSet();
            //ds = con.Get_DataSet(ref ds, "select * from Danhmuc");
            //this.dataGridView1.DataSource = ds.Tables[0];
            //con.Close();
           * */
            //string madm = textBox1.Text;
            ////string tendm = textBox2.Text;
            //clDM = new WFcontrol.BL.cl_Danhmuc(this);
            //clDM.xoa(madm);
        }

        public void Load_Grid()
        {
           /* con.Open();
            String SQL = "select * from DanhMuc";
            tb_danhmuc = con.Get_DataTable(SQL);
            this.dataGridView1.DataSource = tb_danhmuc;
            
            textBox1.DataBindings.Clear();
            textBox2.DataBindings.Clear();
            
            textBox1.DataBindings.Add("Text", tb_danhmuc, "MaDM");
            textBox2.DataBindings.Add("Text",tb_danhmuc,"TenDM");
            
            con.Close();*/
        }

        private void btn_sua_Click(object sender, EventArgs e)
        {
          /*  con.Open();
            String SQL = "update DanhMuc set TenDM ='" + textBox2.Text + "'" + "where MaDM='" + textBox1.Text + "'";
            con.Execute_SQL(SQL);
            con.Close();

            Load_Grid();
            //DataSet ds = new DataSet();
            //ds = con.Get_DataSet(ref ds, "select * from Danhmuc");
            //this.dataGridView1.DataSource = ds.Tables[0];
            //con.Close();*/
            string madm = textBox1.Text;
            string tendm = textBox2.Text;
            clDM = new WFcontrol.BL.cl_Danhmuc(this);
            clDM.sua(madm,tendm);
        }

        private void btn_next_Click(object sender, EventArgs e)
        {
            this.db.Position += 1;
        }

        private void btn_luu_Click(object sender, EventArgs e)
        {
            /*con.Open();
            DataTable tb = (DataTable)dataGridView1.DataSource;
            con.Update_DataSet(ref tb, "select MaDM, TenDM from DanhMuc");
            con.Close();*/
        }

        private void button2_Click(object sender, EventArgs e)
        {
            clDM.sua2();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            clDM.xoa2();
            //dataGridView1.Refresh();
        }

    }
}
